﻿Chenxin.UI.SysSerialNumMgr=Chenxin.extend(Chenxin.UI.PageCommon,{
	actionUrl:'service/SysSerialNumMgr.ashx',
	createGrid:function(){		
		return new Chenxin.UI.Pagination({
			actionUrl:this.actionUrl+'?op=getlist',
			id:'sysserialnum',
			renderTo:'sysserialnum_table',
			data:{}
		});
	},
	handler:function(status){
		var _status=this.getStatus();
		if(status==1&&_status=='有效'){
			alert('该授权已经是激活状态！');
			return;
		}
		if(status==0&&_status=='无效'){
			alert('该授权已经是禁用状态！');
			return;
		}
		this.del('handler',status==1?'确定激活这条授权吗？':'确定禁用这条授权吗？','',{status:status});
	},
	initEvent:function(){
		var _this=this;
		$('#btn_add').click(function(){
            _this.add();
			_this.form.reset();
		});	
		$('#btn_del').click(function(){			        
            _this.del();
        });
		
		$('#btn_edit').click(function(){
            _this.edit();
			_this.form.setTitle('编辑授权！');
        });
		
		$('#btn_active').click(function(){			        
            _this.handler(1);
        });
		
		$('#btn_disable').click(function(){			        
            _this.handler(0);
        });

		$('.tr_houselist').live('click',function(){	
			$('.tr_houselist,.selected_orgbgcolor').each(function(){
				$(this).removeClass('selected_orgbgcolor');	
			});
			_this.currentId=this.id;
			
			$(this).toggleClass('selected_orgbgcolor');	
		});
		$('.tr_houselist').live('mouseover',function(){
			$(this).toggleClass('orgbgcolor');
		});
		$('.tr_houselist').live('mouseout',function(){
			$(this).toggleClass('orgbgcolor');
		});
		
		
	},
	createForm:function(){
		return new Chenxin.UI.SysSerialNumForm({
			scope:this,
			afterGetFormJson:function(model){
				if(this.form.op=='edit'){
					this.form.additionalParam.oldmac=this.currentModel.MACAddress;
				}else{
					if(this.form.additionalParam.oldmac){
						delete this.form.additionalParam.oldmac;
					}
				}
				Chenxin.applyIf(model,this.currentModel);
			},
			saveSucc:function(){
				this.reloadGrid();
			}
		});
	},
	getStatus: function() {
        return $('#' + this.currentId + ' td:eq(6)').text();
    },
	createSearch:function(){
		return new Chenxin.UI.SysSerialNumSearch({
			scope:this
		});
	},
	initComponent:function(){
		Chenxin.UI.SysSerialNumMgr.superclass.initComponent.call(this);
	}
});

Chenxin.UI.SysSerialNumForm=Chenxin.extend(Chenxin.UI.FormCommon,{
	actionUrl:'service/SysSerialNumMgr.ashx',
	id:'sysSerialNumWin',
	renderTo:'jqm_sysSerialNum',
	title:'添加授权',
	jqmWidth:400,
	initFormValidator:function(){
	
        //MAC地址
        $("#MACAddress").formValidator({
			validatorgroup:this.id,
            onshow: "请输入授权号", 
			onfocus: "请输入授权号", 
			oncorrect: " "
        }).inputValidator({ //非空验证
            min: 10, 
			empty: { 
				leftempty: false, 
				rightempty: false, 
				emptyerror: "请输入授权号" 
			}, 
			onerror: "请输入授权号"
        });
		
        //使用人
        $("#UserName").formValidator({
			validatorgroup:this.id,
            onshow: "请填写使用人", 
			onfocus: "请填写使用人", 
			oncorrect: " "
        }).inputValidator({ //非空验证
            min: 1, 
			empty: { 
				leftempty: false, 
				rightempty: false, 
				emptyerror: "请填写使用人" 
			}, 
			onerror: "请填写使用人"
        });
		
        //门店
        $("#Depart").formValidator({
			validatorgroup:this.id,
            onshow: "请填写门店", 
			onfocus: "请填写门店", 
			oncorrect: " "
        }).inputValidator({ //非空验证
            min: 1, 
			empty: { 
				leftempty: false, 
				rightempty: false, 
				emptyerror: "请填写门店" 
			}, 
			onerror: "请填写门店"
        });
	},
	createForm:function(){
		return Chenxin.FormCommon.sysSerialNumForm(this.id);
	},
	
	initEvent:function(){
				
		var _this=this;
		var filter='#'+this.id+'_';
		$(filter+'Save').live('click',function(){
			_this.save();
		});
		$(filter+'Cancle').live('click',function(){
			_this.hide();
		});	
	},
	initComponent:function(){
		Chenxin.UI.SysSerialNumForm.superclass.initComponent.call(this);
	}
});


/**
*查询面板
*/
Chenxin.UI.SysSerialNumSearch=Chenxin.extend(Chenxin.UI.SearchCommon,{
	id:'sysSerialNum_search',
	initEvent:function(){
		var _this=this;
		$('#btn_search').live('click',function(){
			_this.scope.reloadGrid();
		});
		
	},
	createComboList:function(){
		//城市
		var city=new Chenxin.UI.StructCombo({
			param:{op:'getcity'},
			containerId:'#syssn_city',
			name:'cityid',
			tbxWidth:70,
			afterLoadItems:function(){
				if(this.items.length==1){
					this.addPleaseSelected=false;
					company.param.fatherid=this.items[0].val;
					company.reload();
				}else{
					this.addPleaseSelected=true;	
				}
			},
			onSelected:function(){
				if(this.getValue()==this.defVal){
					company.clearItems();
				}else{
					company.param.fatherid=this.getValue();
					company.reload();
				}
			}
		});
		
		//公司
		var company=new Chenxin.UI.StructCombo({
			autoLoad:false,
			param:{op:'getcompany'},
			name:'companyid',
			containerId:'#syssn_company',
			tbxWidth:70,
			afterLoadItems:function(){
				if(this.items.length==1){
					this.addPleaseSelected=false;
					this.initValue=this.items[0].val;
				}else{
					this.addPleaseSelected=true;	
				}
			}
		});
		return [city,company];
	},
	initComponent:function(){
		Chenxin.UI.SysSerialNumSearch.superclass.initComponent.call(this);
	}
});


/**
*@description 楼盘DIV
*@method 提交按钮的处理方法
*/
Chenxin.FormCommon.sysSerialNumForm=function(comboIdPrefix){
        return '<table class="tbl_f"><tbody><th><span class="isfilled">*</span>授权号：</th><td><input type="text" style="width: 160px;" value="" class="inputbox_n fl" name="MACAddress" id="MACAddress" /><div id="MACAddressTip" style="float:left; margin-left: 5px; width: 120px; height: 26px; line-height: 26px; text-align: left;"></div></td></tr><tr><th><span class="isfilled">*</span>门店：</th><td><input type="text" style="width: 160px;" value="" class="inputbox_n fl" name="Depart" id="Depart" /><div id="DepartTip" style="float:left; margin-left: 5px; width: 120px; height: 26px; line-height: 26px; text-align: left;"></div></td></tr><tr><th><span class="isfilled">*</span>使用人：</th><td><input type="text" style="width: 160px;" value="" class="inputbox_n fl" name="UserName" id="UserName" /><div id="UserNameTip" style="float:left; margin-left: 5px; width: 120px; height: 26px; line-height: 26px; text-align: left;"></div></td></tr><tr><th>电话：</th><td><input type="text" style="width: 160px;" value="" class="inputbox_n fl" name="ConstractPhone" maxlength="50" id="ConstractPhone" /><div id="ConstractPhoneTip" style="float:left; margin-left: 5px; width: 120px; height: 26px; line-height: 26px; text-align: left;"></div></td></tr><tr><td colspan="2" align="right"><div style="float:right; margin-right:15px;"><a id="' + comboIdPrefix + '_Save" class="btn_n fl" href="#"><span>确定</span></a><a id="' + comboIdPrefix + '_Cancle"  class="btn_n fl" href="#"><span>取消</span></a></div></td></tr></tbody></table>'
}

$(document).ready(function(){
	var community=new Chenxin.UI.SysSerialNumMgr();
	
	$('#addcomm_msg').jqm({ trigger: false}).jqDrag('.jqDrag');
	$('#addbuild_msg').jqm({ trigger: false}).jqDrag('.jqDrag');

})





















